package org.example.design.designmode.flyweight.ticket;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TicketFacotry {
    private static Map<String,ITicket> pool = new ConcurrentHashMap<>();

    public static ITicket getTicket(String form,String to){
        String key = form+"->"+to;
        if(pool.containsKey(key)){
            System.out.println("从缓存拿"+pool.get(key));
              return  pool.get(key);
        }
        ITicket iT = new TrainTicket(form,to);
        System.out.println("首次查询"+key);
        pool.put(key,iT);
        return  iT;
}
}

